<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>

    <!-- start: Meta -->
    <base href="">
    <meta charset="utf-8">
    <title>GM</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="keyword" content="">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <!-- end: Meta -->

    <!-- start: Mobile Specific -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- end: Mobile Specific -->

    <!-- start: CSS -->
    <link id="bootstrap-style" href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/bootstrap-responsive.min.css" rel="stylesheet">
    <link id="base-style" href="../css/style.css" rel="stylesheet">
    <link id="base-style-responsive" href="../css/style-responsive.css" rel="stylesheet">

    <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <link id="ie-style" href="../css/ie.css" rel="stylesheet">
    <![endif]-->

    <!--[if IE 9]>
    <link id="ie9style" href="../css/ie9.css" rel="stylesheet">
    <![endif]-->

    <!-- start: Favicon -->
    <link rel="shortcut icon" href="../img/favicon.ico">
    <!-- end: Favicon -->

</head>

<body> <div class="row-fluid sortable">
    <div class="box span12">
        <div class="box-header" data-original-title>
            <h2>
                <i class="halflings-icon white edit"></i>
                <span class="break"></span>添加用户卡号
            </h2>
            <div class="box-icon">
                <a href="#" class="btn-setting">
                    <i class="halflings-icon white wrench"></i>
                </a>
                <a href="#" class="btn-minimize">
                    <i class="halflings-icon white chevron-up"></i>
                </a>
                <a href="#" class="btn-close">
                    <i class="halflings-icon white remove"></i>
                </a>
            </div>
        </div>
        <div class="box-content">
            <form class="form-horizontal" id="addForm" action="../card/addCard.do" method="POST">
                <input type="hidden" value="${cid}" name="cid" />
                <fieldset>
                    <label class="control-label" for="num">卡号</label>
                    <div class="form-group controls" style="width: 446px;" title="卡号">
                        <input type="text" class="form-control" name="num" id="num" placeholder="请输入银行卡卡号">
                    </div>

                    <label class="control-label" for="pwd">密码</label>
                    <div class="form-group controls" style="width: 446px;" title="密码">
                        <input type="password" class="form-control" name="pwd" id="pwd" placeholder="请输入银行卡密码">
                    </div>

                    <label class="control-label" for="repwd">确认密码</label>
                    <div class="form-group controls" style="width: 446px;" title="确认密码">
                        <input type="password" class="form-control" name="repwd" id="repwd" placeholder="请再次输入银行卡密码">
                    </div>

                    <label class="control-label" for="relLimit">信用卡额度</label>
                    <div class="form-group controls" style="width: 446px;" title="信用卡额度">
                        <input type="text" class="form-control" name="relLimit" id="relLimit" placeholder="信用卡真实额度">
                    </div>

                    <label class="control-label" for="limit">虚拟额度</label>
                    <div class="form-group controls" style="width: 446px;" title="虚拟额度">
                        <input type="text" class="form-control" name="limit" id="limit" placeholder="我们给客户分配额度">
                    </div>

                    <label class="control-label" for="balance">余额</label>
                    <div class="form-group controls" style="width: 446px;" title="余额">
                        <input type="text" class="form-control" name="balance" id="balance" placeholder="卡上面剩余金额">
                    </div>

                    <label class="control-label" for="ctmStatementDate">客户账单日</label>
                    <div class="form-group controls" style="width: 446px;" title="客户账单日">
                        <input type="text" class="form-control" name="ctmStatementDate" id="ctmStatementDate" placeholder="客户账单日(银行几号出账单?)">
                    </div>

                    <label class="control-label" for="ctmRepaymentDate">客户还款日</label>
                    <div class="form-group controls" style="width: 446px;" title="还款日">
                        <input type="text" class="form-control" name="ctmRepaymentDate" id="ctmRepaymentDate" placeholder="还款日(银行几号出还款?)">
                    </div>

                    <label class="control-label" for="stmStatementDate">系统账单日</label>
                    <div class="form-group controls" style="width: 446px;" title="系统账单日">
                        <input type="text" class="form-control" name="stmStatementDate" id="stmStatementDate" placeholder="账单日(本系统几号出账单?)">
                    </div>

                    <label class="control-label" for="stmRepaymentDate">还款日</label>
                    <div class="form-group controls" style="width: 446px;" title="还款日">
                        <input type="text" class="form-control" name="stmRepaymentDate" id="stmRepaymentDate" placeholder="还款日(本系统几号出还款?)">
                    </div>

                    <label class="control-label" for="status">卡状态</label>
                    <div class="form-group controls" style="width: 446px;" title="卡状态">
                        <select name="status" id="status" data-rel="chosen" name="status">
                            <option value="1">可用</option>
                            <option value="0">冻结</option>
                        </select>
                    </div>

                    <label class="control-label" for="remark">备注</label>
                    <div class="form-group controls" style="width: 446px;" title="还款日">
                        <input type="text" class="form-control" name="remark" id="remark">
                    </div>

                    <label class="control-label" for="ctid">卡类型</label>
                    <div class="form-group controls" style="width: 446px;" title="还款日">
                        <select id="ctid" data-rel="chosen" name="ctid">
                            <c:forEach items="${cardTypeList}" var="cardType">
                                <option value="${cardType.id}">${cardType.name}</option>
                            </c:forEach>
                        </select>
                    </div>

                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">保存</button>
                        <button type="reset" class="btn" onClick="javascript:location.href='../rate/rateList.web'">返回</button>

                    </div>
                </fieldset>
            </form>

        </div>
    </div><!--/span-->

</div><!--/row-->

<!-- start: JavaScript-->

<script src="../js/jquery-1.9.1.min.js"></script>
<script src="../js/jquery-migrate-1.0.0.min.js"></script>

<script src="../js/jquery-ui-1.10.0.custom.min.js"></script>

<script src="../js/jquery.ui.touch-punch.js"></script>

<script src="../js/modernizr.js"></script>

<script src="../js/bootstrap.min.js"></script>

<script src="../js/jquery.uniform.min.js"></script>
<script src="../js/bootstrap-validator/bootstrapValidator.min.js"></script>
<script src="../js/jquery.noty.js"></script>
<script src="../js/common.js"></script>
<script>
    $(function(){
        $('#addForm')
                .bootstrapValidator({
                    feedbackIcons: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },
                    fields: {
                        num: {
                            validators: {
                                notEmpty: {
                                    message: '银行卡号不能为空!'
                                },
                                regexp: {
                                    regexp: /^\d{16}|\d{19}$/,
                                    message: '银行卡号格式不正确'
                                },
                                remote: {
                                    url: 'checkCardNumOnly.do',
                                    message: '银行卡号已经存在'
                                }
                            }
                        },
                        pwd: {
                            validators: {
                                notEmpty: {
                                    message: '银行卡密码不能为空!'
                                },
                                stringLength: {
                                    min: 6,
                                    message: '银行卡密码长度不能小于6位'
                                }

                            }

                        },
                        repwd: {
                            validators: {
                                notEmpty: {
                                    message: '确认密码不能为空!'
                                },
                                stringLength: {
                                    min: 6,
                                    message: '确认密码长度不能小于6位'
                                },
                                identical: {
                                    field: 'pwd',
                                    message: '两次密码不相同'
                                }
                            }
                        },
                        relLimit: {
                            validators: {
                                notEmpty: {
                                    message: '信用卡额度不能为空'
                                },
                                regexp: {
                                    regexp: /^(-?\d+)(\.\d+)?$/,
                                    message: "信用卡额度必须是正数字"
                                },
                                greaterThan: {
                                    value: 1000,
                                    message: '信用卡额度必须小于1000'
                                },
                                lessThan: {
                                    value: 30000,
                                    message: '信用卡额度必须大于30000'
                                }
                            }
                        },
                        limit: {
                            validators: {
                                notEmpty: {
                                    message: '临时额度不能为空'
                                },
                                regexp: {
                                    regexp: /^(-?\d+)(\.\d+)?$/,
                                    message: "虚拟额度必须是正数字"
                                },
                                greaterThan: {
                                    value: 100,
                                    message: '临时额度必须大于100'
                                },
                                lessThan: {
                                    value: 30000,
                                    message: '临时额度必须小于30000'
                                },
                                callback: {
                                    message: '临时额度不能大于信用卡真实额度',
                                    callback: function(value, validator) {
                                        var relLimit = parseInt($('#relLimit').val());
                                        return relLimit >= value;
                                    }
                                }
                            }
                        },
                        balance: {
                            validators: {
                                notEmpty: {
                                    message: '信用卡余额不能为空'
                                },
                                regexp: {
                                    regexp: /^(-?\d+)(\.\d+)?$/,
                                    message: "信用卡余额必须是正数字"
                                }
                            }
                        },
                        ctmStatementDate: {
                            validators: {
                                notEmpty: {
                                    message: '账单日不能为空'
                                },

                                regexp: {
                                    regexp: /^\+?[1-9][0-9]*$/,
                                    message: '账单日必须是数字'
                                },
                                greaterThan: {
                                    value: 0,
                                    message: '账单日大于0'
                                },
                                lessThan: {
                                    value: 31,
                                    message: '账单日小于31'
                                }
                            }
                        },
                        ctmRepaymentDate: {
                            validators: {
                                notEmpty: {
                                    message: '还款日不能为空'
                                },

                                regexp: {
                                    regexp: /^\+?[1-9][0-9]*$/,
                                    message: '还款日必须是数字'
                                },
                                greaterThan: {
                                    value: 0,
                                    message: '还款日大于0'
                                },
                                lessThan: {
                                    value: 31,
                                    message: '还款日小于31'
                                }
                            }
                        },
                        stmStatementDate: {
                            validators: {
                                notEmpty: {
                                    message: '账单日不能为空'
                                },

                                regexp: {
                                    regexp: /^\+?[1-9][0-9]*$/,
                                    message: '账单日必须是数字'
                                },
                                greaterThan: {
                                    value: 0,
                                    message: '账单日大于0'
                                },
                                lessThan: {
                                    value: 28,
                                    message: '账单日小于28'
                                }
                            }
                        },
                        stmRepaymentDate: {
                            validators: {
                                notEmpty: {
                                    message: '还款日不能为空'
                                },

                                regexp: {
                                    regexp: /^\+?[1-9][0-9]*$/,
                                    message: '还款日必须是数字'
                                },
                                greaterThan: {
                                    value: 0,
                                    message: '还款日大于0'
                                },
                                lessThan: {
                                    value: 28,
                                    message: '还款日小于28'
                                }
                            }
                        }

                    }
                })
                .on('success.form.bv', function(e) {
                    // Prevent form submission
                    e.preventDefault();

                    var $form = $(e.target);

                    //Use Ajax to submit form data
                    ajaxParam($form.attr('action'), $form.serialize(), 10000, 'POST', 'json', doSuccess);

                    function doSuccess(res) {
                        console.log(res);
                        if(res.status == 100){
                            noty({"text":"新增成功","layout":"top","type":"success"});
                            setTimeout(function () {
                                window.location.href="cardList.web";
                            }, 3000);
                        }else{
                            noty({"text":res.error,"layout":"top","type":"alert","closeButton":"true"});
                        }
                    }

                });
    });
</script>
</body>
</html>
